new Vue({
    el: '#activity',
    data: {
        userNames: "",
        pageInfos:{},
        pageInfo: {},
        giftList: {},
		uid:{}
    }, methods: {
		
		exit: function(){
			var adminAccout = sessionStorage.getItem("adminAccout");
			$.ajax({
				type: "get",
				url: "/server/admin/adminExit?adminAccout="+adminAccout,
				async: true,
				data: {
					
				},
				success: function(data) {
					if(window.confirm('是否退出当前账号'))
					{ 
						window.location.href = "/ComeOnProject01/html/Super/SuperAdminLogin.html"
						return true; 
					}else{
						return false;
					}
					
				}
			})
		},
        method: function (num) {
            var self = this;
            //拿到url带的参数
            self.userNames = self.getQueryString('uid');
            console.log("self.userNames:" + self.userNames);
            $.ajax({
                url: '/server/activity/getAllActivity?uid=' + encodeURI(self.userNames)+'&id='+num,
                type: 'get',
                data: {},
                dataType: 'json'
            }).then(function (res) {
                console.log(res.data.list);
                //把从json获取的数据赋值给数组
                self.pageInfo = res.data;
                console.log("后台返回的数据：" + self.pageInfo)
            }).fail(function () {
                console.log('失败');
            })
        },
        //分割拿到的url路径并得到参数
        getQueryString: function (name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            console.log("路径:" + window.location.href);
            var r = window.location.search.substr(1).match(reg);
            console.log("url参数:" + r);
            if (r != null) {
                return encodeURI(unescape(r[2]));
            } else {
                return null;
            }
        },
        //向后台发送礼物清单的请求
        gift: function (activityId,cid) {
            var self = this;
            axios.get("/server/gift/getGiftByActivityId?activityId="+activityId+"&&id="+cid, {
            }).then(function (response) {
                console.log(response);
                console.log("需要的json数据");
                console.log(response.data.data);
                self.giftList = response.data.data;
                console.log("赋值之后的数据");
                console.log(self.giftList);
                $('#myModal').modal("show");
            }).catch(function (err) {
                console.log("礼物清单数据拉取失败"+err)
            });
        },
        //向后台发送礼物清单的分页请求
        giftMehod: function (activityId,gid) {
            var self = this;
            axios.get("/server/gift/getGiftByActivityId?activityId="+activityId+"&&id=" + gid, {
            }).then(function (response) {
                console.log(response);
                console.log("需要的json数据2");
                console.log(response.data.data);
                self.giftList = response.data.data;
                console.log("赋值之后的数据2");
                console.log(self.giftList);
                $('#myModal').modal("show");
            }).catch(function (err) {
                alert("没有这么多页数,点不了!");
                console.log("礼物清单数据拉取失败"+err)
            });
        },
		//向服务器发起终止活动的请求
		termination: function (activityId,id) {
			var self = this;
			axios.get("/server/activity/activity/" + activityId, {
			}).then(function (response) {
			    //self.giftList = response.data.data;
				alert("该活动已经被强行停止");
			}).catch(function (err) {
			    console.log("终止活动请求失败"+err)
			});
		    	
		}


},

    created: function () {
        //为了在内部函数能使用外部函数的this对象，要给它赋值了一个名叫self的变量。
        var self = this;
        //拿到url带的参数
        self.userNames = self.getQueryString('uid');
        console.log("self.userNames:" + self.userNames);
        $.ajax({
            url: '/server/activity/getAllActivity?uid=' + self.userNames,
            type: 'get',
            data: {},
            dataType: 'json'
        }).then(function (res) {
            console.log(res.data);
            //把从json获取的数据赋值给数组
            self.pageInfo = res.data;
            console.log("后台返回的数据：" + self.pageInfo)
        }).fail(function () {
            console.log('失败');
        })
    },
});
